package com.sheliduan.itlearning.blogger.controller;

import cn.hutool.http.server.HttpServerRequest;
import com.sheliduan.itlearning.blogger.model.vos.course.*;
import com.sheliduan.itlearning.blogger.service.BloggerCourseService;
import com.sheliduan.itlearning.common.aspect.ApiOperationLog;
import com.sheliduan.itlearning.common.domain.mapper.ArticleCourseMapper;
import com.sheliduan.itlearning.common.domain.mapper.CategoryMapper;
import com.sheliduan.itlearning.common.domain.mapper.TagMapper;
import com.sheliduan.itlearning.common.domain.mapper.VideoCourseMapper;
import com.sheliduan.itlearning.common.model.vos.IdReqVO;
import com.sheliduan.itlearning.common.model.vos.IdTypeReqVO;
import com.sheliduan.itlearning.common.utils.PageResponseData;
import com.sheliduan.itlearning.common.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;

/**
 * @author: 断舍离
 * @date: 2025/2/20 10:25
 * @description: 博主课程管理控制器
 **/
@RestController
@RequestMapping("/blogger")
public class BloggerCourseController {

    @Autowired
    private BloggerCourseService bloggerCourseService;

    @Autowired
    private ArticleCourseMapper articleCourseMapper;

    @Autowired
    private VideoCourseMapper videoCourseMapper;

    /*
     * 分页查询课程
     * */
    @PostMapping("/course/pageList")
    @ApiOperationLog(description = "课程数据分页查询")
    public PageResponseData findCoursePageList(@RequestBody @Validated FindCoursePageListReqVO findCoursePageListReqVO){
        if(findCoursePageListReqVO.getType() == 0) {
            return bloggerCourseService.findArticleCoursePageList(findCoursePageListReqVO);
        } else {
            return bloggerCourseService.findVideoCoursePageList(findCoursePageListReqVO);
        }
    }

    /*
     * 添加课程(有保存和发布两个按钮, 传的状态是不一样的)
     * */
    @PostMapping("/course/add")
    @ApiOperationLog(description = "添加课程")
    public ResponseData addCourse(@RequestBody @Validated AddCourseReqVO addCourseReqVO) {
        if(addCourseReqVO.getType() == 0) {
            return bloggerCourseService.addArticleCourse(addCourseReqVO);
        }else {
            return bloggerCourseService.addVideoCourse(addCourseReqVO);
        }
    }

    /*
     * 删除课程
     * */
    @PostMapping("/course/delete")
    @ApiOperationLog(description = "删除课程")
    public ResponseData deleteCourse(@RequestBody @Validated DeleteCourseReqVO deleteCourseReqVO){
        return bloggerCourseService.deleteCourse(deleteCourseReqVO);
    }

    /*
     * 修改课程
     * */
    @PostMapping("/course/update")
    @ApiOperationLog(description = "修改课程")
    public ResponseData updateCourse(@RequestBody @Validated UpdateCourseReqVO updateCourseReqVO){
        if(updateCourseReqVO.getType() == 0) {
            return bloggerCourseService.updateArticleCourse(updateCourseReqVO);
        }else {
            return bloggerCourseService.updateVideoCourse(updateCourseReqVO);
        }
    }

    /*
     * 根据id和type查找课程
     * */
    @PostMapping("/course/selectById")
    @ApiOperationLog(description = "根据id和type查找课程")
    public ResponseData selectById(@RequestBody @Validated IdTypeReqVO idTypeReqVO) {
        return bloggerCourseService.selectById(idTypeReqVO);
    }

    /*
    * 投稿课程
    * */
    @PostMapping("/course/contribute")
    @ApiOperationLog(description = "投稿课程")
    public ResponseData contributeCourse(@RequestBody @Validated UpdateCourseStatusReqVO updateCourseStatusReqVO) {
        return bloggerCourseService.updateCourseStatus(updateCourseStatusReqVO);
    }

}
